<%--
  Created by IntelliJ IDEA.
  User: wyp
  Date: 2020/5/12
  Time: 8:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--引入JQuery，必须要在bootstrap.js之前引入-->
    <script type="text/javascript" src="./resources/js/jquery-3.4.1.min.js"></script>
    <link rel="stylesheet" href="./resources/css/font.css">
    <link rel="stylesheet" href="./resources/css/xadmin.css">
    <!-- <link rel="stylesheet" href="./css/theme5.css"> -->
    <script src="./resources/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./resources/js/xadmin.js"></script>
    <title>Title</title>
</head>
<body>
<script>
    $(document).ready(function () {
        // 获取地址栏id
        var getUserId = getQueryVariable("userId");
        console.log(getUserId);
        getSpotInfo(getUserId);
    });

    // 获取地址栏参数
    function getQueryVariable(variable)
    {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
        }
        return(false);
    }

    //根据id查找用户信息
    function getSpotInfo(userId) {
        $.ajax({
            type: "POST",
            dataType: "json",
            data:{"method":"userGetByuserId","userId":userId},
            url:"./userController",
            success:function (data) {
                console.log(data);
                document.getElementById("userSalt").value = data.userSalt;
                document.getElementById("userId").value = data.userId;
                document.getElementById("userName").value = data.userName;
                document.getElementById("userPassword").value = data.userPassword;
                document.getElementById("userTel").value = data.userTel;
                document.getElementById("userSex").value = data.userSex;
                document.getElementById("userRole").value = data.userRole;
            }
        });
    }

    //更新景点
    layui.use(['form', 'layer','jquery'],
        function() {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;


            //监听提交
            form.on('submit(userUpdate)',
                function(data) {
                    console.log(data);
                    //发异步，把数据提交给后台
                    var userSalt = $('#userSalt').val();
                    var userId = $('#userId').val();
                    var userName = $('#userName').val();
                    var userPassword = $('#userPassword').val();
                    var userTel = $('#userTel').val();
                    var userSex = $('#userSex').val();
                    var userRole = $('#userRole').val();
                    console.log("updataSpot测试");

                    $.ajax({
                        type:"POST",
                        dataType: "json",
                        url:"./userController",
                        data:{"method":"userUpdate","userId":userId,"userName":userName,"userPassword":userPassword,"userTel":userTel,"userSex":userSex,"userRole":userRole,"userSalt":userSalt},
                        success:function(data){
                            layer.alert("更新成功", {
                                    icon: 6
                                },
                                function() {
                                    // 获得frame索引
                                    var index = parent.layer.getFrameIndex(window.name);
                                    //关闭当前frame
                                    parent.layer.close(index);
                                    xadmin.father_reload();
                                });
                        }
                    });
                    return false;
                });

        });

</script>
<%--用来存储userId 和加密--%>
<input type="text" style="display: none" id="userId" name="userId">
<input type="text" style="display: none" id="userSalt" name="userSalt">
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="userName" class="layui-form-label">
                    <span class="x-red">*</span>用户名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="userName" name="userName" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" readonly="readonly">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">*</span>密码(清空为不修改)</label>
                <div class="layui-input-inline">
                    <input type="text" id="userPassword" name="userPassword" required="" lay-verify="spotImgUrl"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="userTel" class="layui-form-label">
                    <span class="x-red">*</span>联系电话
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="userTel" name="userTel" required="" lay-verify="spotPlace"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="userSex" class="layui-form-label">
                    <span class="x-red">*</span>性别（1男0女）
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="userSex" name="userSex" required="" lay-verify="spotItem"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="userRole" class="layui-form-label">
                    <span class="x-red">*</span>身份
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="userRole" name="userRole" required="" lay-verify="spotItem"
                           autocomplete="off" class="layui-input">
                </div>
            </div>




            <div class="layui-form-item">
                <label for="userRole" class="layui-form-label">
                </label>
                <button  class="layui-btn" lay-filter="userUpdate" lay-submit="" >
                    修改
                </button>
            </div>


        </form>
    </div>
</div>
</body>
</html>
